package edu.sctu.practice.class01.fengleilin.assign03.test03;

/**
 * Created by fll on 2015/10/22.
 */

/**
 * 程序的主方法中使用clone方法完成两个CloneableCircle类对象的深拷贝
 */
public class Main {
    public static void main(String[] args) throws CloneNotSupportedException {
        //原始对象
        Name name = new Name();
        name.firstName = "Martin ";
        name.middlName = "Lurther ";
        name.lastName = "King";

        CloneableCircle circle = new CloneableCircle();
        circle.setCreator(name);
        System.out.println("原始对象: " + name.firstName + name.middlName + name.lastName);

        //拷贝对象
        CloneableCircle cloneCircle = (CloneableCircle) circle.clone();
        cloneCircle.getCreator().firstName = "Thomas ";
        cloneCircle.getCreator().middlName = "William ";
        cloneCircle.getCreator().lastName = "Hiddleston";

        System.out.println("拷贝对象: " + cloneCircle.getCreator().firstName + cloneCircle.getCreator().middlName + cloneCircle.getCreator().lastName);

        // 原始对象和拷贝对象是否一样：
        if (cloneCircle.equals(name)) {
            System.out.println("没有实现对象内容深拷贝");
        } else {
            System.out.println("实现了对象内容深拷贝");
        }


    }
}
